// app.js
App({
  onLaunch() {
    const that = this;
    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();
    // 胶囊按钮位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    that.globalData.navBarHeight = systemInfo.statusBarHeight + menuButtonInfo.height + (menuButtonInfo.top - systemInfo.statusBarHeight) * 2;
    that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
    that.globalData.menuTop = menuButtonInfo.top;
    that.globalData.menuBotton = menuButtonInfo.top - systemInfo.statusBarHeight;
    that.globalData.menuHeight = menuButtonInfo.height;

    const { miniProgram: { envVersion } } = wx.getAccountInfoSync();
    this.globalData.hide = true
    switch (envVersion) {
      case 'develop':
        this.globalData.hide = false;
        break;
      case 'trial':
        this.globalData.hide = true;
        break;
      case 'release':
        this.globalData.hide = false;
        break;
      default:
        this.globalData.hide = false;
        break;
    }

    this.overShare();
  },
  globalData: {
    hide: false,
    userInfo: null,
    navBarHeight: 0, // 导航栏高度
    menuRight: 0, // 胶囊距右方间距（方保持左、右间距一致）
    menuTop: 0,
    menuBotton: 0, // 胶囊距底部间距（保持底部间距一致）
    menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
  },
  // 全局分享
  overShare: function () {
    //间接实现全局设置分享内容
    wx.onAppRoute(function (res) {
      //获取加载的页面
      let pages = getCurrentPages(),
        //获取当前页面的对象
        view = pages[pages.length - 1],
        data;
      if (view) {
        data = view.data;
        if (!data.isOverShare) {
          data.isOverShare = true;
          // console.log('全局分享参数：', _this.getShareUrlParams())
          view.onShareAppMessage = function () {
            //重写分享配置
            return {
              title: "陈陈小商铺",
              path: "/pages/index/index", //分享页面地址
              imageUrl: "/static/images/share.png",
            };
          };
          view.onShareTimeline = function () {
            //重写分享配置
            return {
              title: "陈陈小商铺",
              imageUrl: "/static/images/share.png",
            };
          };
        }
      }
    });
  },
});
